using System.Linq;
using Demo.Business;
using MvpFramework.Specifications;

namespace Demo.Presentation
{
    public class CanNotHaveSameNameSpecification : Specification<IEditPersonView>
    {
        private readonly IPersonRepository repository;

        public CanNotHaveSameNameSpecification(IPersonRepository repository)
        {
            this.repository = repository;
        }

        public override bool IsSatisfiedBy(IEditPersonView obj)
        {
            return repository.GetAll().FirstOrDefault(p => p.Name == obj.Name) == null;
        }
    }
}